<template>
    <div class="process">
        <div class="processDetail" v-if="processDetailFlag">
            <div class="dialogTitle">
                <p>{{ currentDetailTitle }}</p>
                <el-icon color="#333" style="font-size: 12px" @click="closed">
                    <Close />
                </el-icon>
            </div>
            <el-scrollbar max-height="306px" style="padding-top: 8px">
                <div v-if="currentDetailList.length">
                    <div
                        class="itemdetail"
                        v-for="item in currentDetailList"
                        :key="item.name"
                    >
                        <p>{{ item.facilityName }}</p>
                        <p
                            :style="{
                                color:
                                    item.facilityState == '1'
                                        ? '#409eff'
                                        : 'orange',
                            }"
                        >
                            {{ item.facilityState == "1" ? "在用" : "维修" }}
                        </p>
                    </div>
                </div>
                <div class="empty" v-else>暂无数据</div>
            </el-scrollbar>
        </div>
        <v3-drag-zoom-container
            :minZoom="minZoom"
            :maxZoom="3"
            :style="{
                width: innerWidth + 'px',
                height: innerHeight + 'px',
            }"
        >
            <div
                class="flex-column flex-same processFlowImg"
                :style="{
                    width: innerWidth + 'px',
                    height: innerWidth / 2 + 'px',
                }"
            >
                <div
                    v-for="item in points"
                    :key="item.pointName"
                    class="eqPoint"
                    :style="{
                        left: item.x + 'px',
                        top: item.y + 'px',
                    }"
                    @click="processFlowDetail(item)"
                >
                    <div class="pointName" style="z-index: 9000">
                        {{ item.pointName }}
                    </div>
                    <img
                        class="pointIcon"
                        src="../../../../../assets/location1.png"
                        alt=""
                    />
                </div>
            </div>
        </v3-drag-zoom-container>
    </div>
</template>
<script setup>
import {
    getPointList1920,
    getPointList1680,
    getPointList1440,
} from "./constants.js";
import { Close } from "@element-plus/icons-vue";
import equipmentHttp from "@/https/equipment.js";
import { onMounted, ref, reactive } from "vue";
const innerHeight = ref(0);
const innerWidth = ref(0);
const minZoom = ref(1);
const points = ref([]);
const screenResolution = ref(window.screen.width);
console.log(
    screenResolution.value,
    screenResolution.value == "1920",
    screenResolution.value == "1680",
    screenResolution.value == "1440",
    screenResolution.value == "1280",
    window.innerWidth
);
// if (screenResolution.value == "1680" || screenResolution.value == "1600") {
//     points.value = getPointList1680();
// } else if (screenResolution.value == "1920") {
//     points.value = getPointList1920();
// } else if (
//     screenResolution.value == "1440" ||
//     screenResolution.value == "1280"
// ) {
//     points.value = getPointList1440();
// } else {
// }
points.value = getPointList1920();
const processDetailFlag = ref(false);
const currentDetailTitle = ref("");
const currentDetailList = ref([]);
innerWidth.value = window.innerWidth - 250;
innerHeight.value = window.innerHeight - 190;
const processFlowDetail = async (item) => {
    console.log(item);
    if (item.pointChildList.length > 0) {
        processDetailFlag.value = true;
        currentDetailTitle.value = item.pointName;
        currentDetailList.value = item.pointChildList;
    } else {
        processDetailFlag.value = true;
        currentDetailTitle.value = item.pointName;
        currentDetailList.value = item.pointChildList;
    }
};
const closed = () => {
    processDetailFlag.value = false;
};
let searchForm = reactive({
    assetNumber: "",
    depId: "",
    facilityLevel: "",
    facilityLocations: "",
    facilityName: "",
    facilitySort: "",
    facilityState: "",
    facilitySupplier: "",
    specificationModel: "",
    pageNo: 1,
    pageSize: 1000,
});
const search = (depId, facilityLocations) => {
    let params = {
        ...searchForm,
        depId: depId,
        facilityLocations: facilityLocations,
    };
    equipmentHttp.queryFacility(params).then((res) => {
        if (res.data.code == 200) {
            points.value.forEach((item) => {
                if (facilityLocations == item.pointName) {
                    item.pointChildList = res.data.data.records;
                }
            });
        }
    });
};
const widthScale = ref(0);
widthScale.value = innerWidth.value / 1190;
// const heightScale = ref(0);
// heightScale.value = innerHeight.value / 595;
onMounted(() => {
    // if (screenResolution.value == "1440") {
    points.value.forEach((item) => {
        item.x = item.x * widthScale.value;
        item.y = item.y * widthScale.value;
    });
    // }
    search("5", "一期预处理");
    search("5", "二期预处理");
    search("5", "二号二沉池");
    search("5", "一号二沉池");
    search("5", "三号二沉池");
    search("5", "四号二沉池");
    search("5", "一期污泥泵房");
    search("5", "二期回流泵房");
    search("5", "中间提升泵房");
    search("5", "反硝化前池");
    search("5", "除磷反应池");
    search("5", "反硝化");
    search("5", "超滤膜车间");
    search("5", "脱泥间");
    search("5", "二期三号氧化沟");
    search("5", "二期四号氧化沟");
    search("5", "二期鼓风机房");
    search("5", "一期一号氧化沟");
    search("5", "一期二号氧化沟");
    search("5", "一期鼓风机房");
    search("5", "一期提升泵房");
    search("5", "二期提升泵房");
});
</script>
<style lang="less">
.processFlowImg {
    background: url("../../../../../assets/factorySmall.jpg");
    background-size: cover;
    position: relative;
}
.eqPoint {
    position: absolute;
    .pointName {
        position: absolute;
        line-height: 2;
        background: #fff;
        border-radius: 4px;
        font-size: 12px;
        display: none;
        top: -30px;
        left: 50%;
        transform: translateX(-50%);
        word-wrap: normal;
        min-width: 100px;
        text-align: center;
    }
    &:hover {
        .pointIcon {
            scale: 1.3;
        }
        .pointName {
            display: block;
        }
    }
    .pointIcon {
        width: 20px;
        height: 20px;
        scale: 1;
    }
}
.process {
    position: relative;
}
.processDetail {
    position: absolute;
    width: 220px;
    height: 380px;
    background: #fff;
    left: 40px;
    top: 40px;
    z-index: 10000;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    font-size: 13px;
}
.dialogTitle {
    font-size: 14px;
    line-height: 3;
    padding: 0 10px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #ccc;
    font-weight: 600;
}
.itemdetail {
    line-height: 2.5;
    padding: 0 15px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}
.empty {
    width: 100%;
    text-align: center;
    line-height: 2.5;
}
</style>